//引入http组件
const http = require('http')
//创建一个服务器
const server = http.createServer();
//运行这个服务器
server.on('request',function(req,res){
// const str=`您请求的url是：${req.url},您请求的method是：${req.method}`

const url = req.url;
let content = '444 not found';
if(url==='/'||url==='/index.html'){
  content = '<h1>首页</h1>'
  
}  else if(url==='/about.html'){
  content = '<h1>关于页面</h1>'
} 
res.setHeader('Content-Type','text/html; charset=utf-8') ; 
res.end(content)
})



server.listen(8082, function(){
  console.log('server running on http://127.0.0.1:8082');
console.log('服务器已经启动');
})